- Git
- what is Git?
- installing Git on your machine
- basic commands
- setting up a Git repo on a local machine
- GitHub
- what is GitHub?
- signing up
- connecting your local Git repo to GitHub
- selecting an awesome avatar will not be covered
July 27, 2017
There are a lot of different ways to use Git, for example, the command line, one of several desktop applications, and even within RStudio.
Installation is rather straightforward: https://git-scm.com/downloads. Just follow the instructions for your particular operating system
Tip: Windows users, you should install from here: https://git-for-windows.github.io/
After Git is successfully installed, open up a terminal and write (with the obvious modifications) the following two lines:
$ git config --global user.name "Brandon Greenwell" $ git config --global user.email greenwell.brandon@gmail.com
Note: Since you passed the option --global, you only need to do this once!
Note: Technically, you don't need to do this step, but you should!
Note: Windows users should use the Bash terminal that was installed with Git, not the normal Windows command line!
cd (change directories)git init (initialize a folder as a Git repo)git add <file-name> (start tracking a new file)git commit -m "fix typo" (commit your changes)git clone (clone/copy another Git repo [e.g., from GitHub])git push origin master (push your master branch to your origin server)git pull origin master (update your local repo)Tip: Typing git add --all will start tracking everything (this is how I almost always use git add).
Make a new folder called arithmetic anywhere on your computer (e.g., the Desktop) that contains a single R script called add.R containing the function
add <- function(x, y) {
x * y
}
If you want to begin tracking an existing project in Git, you need to start by going to the project's root directory. For example,
cd C:/Users/greenweb/Desktop/arithmetic
takes me to the folder called arithmetic on my Desktop. Then, to initialize this as a Git repo, just type
git init
Tip: the command line has a history (just like the R console), so you don't need to type as often; just hit the up arrow and make any necessary changes!
If you want to start version controlling all the files, you need to start tracking them. In the terminal, type the following:
git add --all
then type:
git commit -m "first commit"
The first thing you need to do is set up an account: https://github.com/
Use the same e-mail address you used when setting up Git!
Refresh your browswer and see if it worked!
Fix the obvious typo in add.R. Then, take a snapshot (i.e., git add/commit) and push the changes to GitHub (i.e., git push)!
git add --all git commit -m "fix typo" git push origin master
Refresh your browser to see the changes.
Tip: It's good practice to do this every time you make a key change (e.g., fix a typo, add a new function to an R script, etc.).
* Make sure you're in the right directory!
Any questions?